package com.example.demo.controller

import com.example.demo.bean.UserBean
import com.example.demo.service.UserDaoService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/home")
class UserController {
    @Autowired
    private lateinit var loginService: UserDaoService

    //登录
    @PostMapping("login")
    fun login(@RequestParam("username") username:String,@RequestParam("pwd") pwd:String):UserBean{

        var userBean:UserBean?
        userBean = this.loginService.login(username,pwd)

        return userBean!!

    }
    //登录
    @PostMapping("register")
    fun register(@RequestParam("username") username:String,@RequestParam("pwd") pwd:String,@RequestParam("phone") phone:String):Boolean{

//        return  false

        return this.loginService.register(username,pwd,phone)!!

    }
    //登录
    @PostMapping("delete")
    fun delete(@RequestParam("username") username:String):Boolean{

        return this.loginService.delete(username)!!

    }
    //登录
    @PostMapping("update")
    fun update(@RequestParam("phone") phone:String):Boolean{

        return this.loginService.update(phone)!!

    }
    @RequestMapping("hello")
    fun Helllo():String{


        return "HelloWord"

    }
}